package com.okaixz.manager.utils;

import com.okaixz.manager.domain.UserThreadContext;

public class BaseContext {
    private static ThreadLocal<UserThreadContext> threadLocal = new ThreadLocal<>();

    public static UserThreadContext getUserContext(){
        UserThreadContext userThreadContext = threadLocal.get();
        if (userThreadContext == null) {
            userThreadContext=new UserThreadContext();
            threadLocal.set(userThreadContext);
        }
        return userThreadContext;
    }

    public static void setUserId(String id) {
        UserThreadContext userThreadContext = getUserContext();
        userThreadContext.setUserId(id);
    }

    public static String getUserId() {
        String aLong = getUserContext().getUserId();
        return aLong;
    }
    public static int getHttpVersion() {
        return getUserContext().getHttpVersion();
    }

    public static void setHttpVersion(String version){
        int versionCode=0;
        try {
            versionCode=Integer.valueOf(version);
        } catch (Exception e) {
            e.printStackTrace();
        }
        getUserContext().setHttpVersion(versionCode);
    }

    public static void clean() {
        threadLocal.remove();
    }


}
